<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of pagination
 *
 * @author ptnhuan
 */
class Pagination {

    //put your code here
    public function display($total, $page) {
        $html = '';

        $pages = $total / PER_PAGE;
        $count = 1;

        if ($page > 0 && $page <= 5) {
            for ($i = 1; $i < 10; $i++) {
                $html .= ' ' . "<a href='index.php?page=$i'>$i</a>";
            }
        } else if ($page > $pages - 5 && $page <= $pages) {
            for ($i = $pages - 8; $i <= $pages; $i++) {
                $html .= ' ' . "<a href='index.php?page=$i'>$i</a>";
            }
        } else {
            $html = "<a href='index.php?page=$page'>$page</a>";
            while ($count < PER_PAGE / 2) {
                if ($page + $count <= $pages) {
                    $li = $page + $count;
                    $html .= ' ' . "<a href='index.php?page=$li'>$li</a>";
                }
                if ($page - $count > 0) {
                    $li = $page - $count;
                    $html = "<a href='index.php?page=$li'>$li</a>" . ' ' . $html;
                }
                $count++;
            }
        }
        return $html;
    }

}

?>
